<template>
	<view class="">
		<view class="">
			<slideshow :swiperList="swiperList"></slideshow>
		</view>
		<view class="pd20">
			<ad style="width: auto; !important" :unit-id="'p7wveuhew8nt0u2j5u'"></ad>
		</view>
		<view class="pd20">
			<view class="user-item" v-for="(item,index) in framerList" :key="index">
				<view class="user-box" @tap="toAuthorDetails(item,index)">
					<view class="img-box">
						<image :src="item.home_profile"
							style="background: #ccc;width: 70rpx;height: 70rpx;border-radius: 50%;" mode=""></image>
					</view>
					<view class="name">
						{{item.home_name}}
					</view>
				</view>
				<wallpaperList v-if="item.imgs_list.length != 0" :wallpaperList="item.imgs_list"></wallpaperList>
				<dataNo v-else></dataNo>
			</view>

			<view class="" style="text-align: center;margin-top: 30rpx;" v-if="pageIndex != 1">
				{{none}}
			</view>
		</view>
	</view>
</template>

<script>
	import wallpaperList from "@/components/common/wallpaper-list.vue"
	import slideshow from "@/components/common/slideshow.vue"
	export default {
		components: {
			slideshow,
			wallpaperList
		},
		data() {
			return {
				framerList: [],
				swiperList: [],
				none: "",
				pageIndex: 1,
				getImgsListIndex: 0
			}
		},
		onLoad() {
			this.getBanner()
			this.getFramer()
		},
		onReachBottom() {
			// this.adUnitIdbanner = this.advertisingData1(this.advertisingDataType.bannerList)
			if (this.none) {
				return
			}
			++this.pageIndex

			this.getFramer()
		},
		methods: {
			toAuthorDetails(item, index) {
				uni.navigateTo({
					url: "/pages/common/author-details?framer_id=" + item.home_code + '&framer_name=' + item
						.home_name
				})
			},
			// 获取创作者
			async getFramer() {
				var data = await this.$api.getData({
					dbName: "wx_framer",
					pageIndex: this.pageIndex,
					pageSize: 10
				})
				if (data.rows.length != 0) {
					this.framerList = [...this.framerList, ...data.rows]
					this.getImgsList()
				} else {
					this.none = '没有数据了'
				}

			},
			// 获取图片
			async getImgsList() {
				const db = uniCloud.database();
				const dbCmd = db.command;
				var userInfo = uni.getStorageSync('userInfo') || {}
				if(!this.framerList[this.getImgsListIndex]){
					return
				}
				console.log(this.framerList[this.getImgsListIndex].home_code,'1212')
				var data = await this.$api.getData({
					dbName: "wx_imgs",
					sortRule:[
						{
							"name": "add_data",
							"type": "asc"
						}
					],
					whereJson: {
						status: 1,
						framer_id:this.framerList[this.getImgsListIndex].home_code
					},
					pageIndex: 1,
					pageSize: 10
				})
				if (data.rows[0]) {
					if (this.framerList[this.getImgsListIndex]) {
						this.framerList[this.getImgsListIndex].imgs_list = data.rows
					}
				}
				++this.getImgsListIndex
				if (this.framerList[this.getImgsListIndex]) {
					this.getImgsList()
				}
			},
			async getBanner() {
				var data = await this.$api.getData({
					dbName: "wx_banner",
					pageIndex: 1,
					pageSize: 10,
					sortRule: [
						{
							name: 'sort',
							type: 'desc'
						}
					]
				})
				this.swiperList = data.rows.filter(item => {
					return item.site == 3 || item.site == 1
				})
			}
		}
	}
</script>
<style>
	page {
		background: #f1f1f1;
	}
</style>
<style scoped lang="scss">
	.pd20 {
		padding: 0 20rpx;
	}

	.user-item {
		margin-bottom: 30rpx;
	}

	.user-box {
		display: flex;
		align-items: center;

		.img-box {
			margin-right: 10rpx;
		}
	}
</style>
